/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FormRegistrarArbitros.java
 *
 * Created on 10-dic-2011, 22:04:09
 */
package Vista;
import Modelo.Arbitros;
import Modelo.Validaciones;
import java.awt.event.ActionListener;
/**
 *
 * @author Angge
 */
public class FormRegistrarArbitros extends javax.swing.JFrame {
int posicion=0;
    /** Creates new form FormRegistrarArbitros */
    public FormRegistrarArbitros() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButtonGuardar = new javax.swing.JButton();
        jButtonEliminar = new javax.swing.JButton();
        jButtonCancelar = new javax.swing.JButton();
        jButtonConsultar = new javax.swing.JButton();
        jButtonVolver = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jTextFieldCedula = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldNombre = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldApellido = new javax.swing.JTextField();
        jFormattedTextFieldFechaNac = new javax.swing.JFormattedTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jTextFieldJuegos = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Registrar Datos Arbitros");
        setBackground(new java.awt.Color(153, 204, 255));
        setForeground(java.awt.Color.white);
        setName("formregistrararbitros"); // NOI18N

        jButtonGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Archivos/Floppy-drive-icon1.png"))); // NOI18N
        jButtonGuardar.setText("GUARDAR");

        jButtonEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Archivos/Button-Delete-icon1.png"))); // NOI18N
        jButtonEliminar.setText("ELIMINAR");

        jButtonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Archivos/Button-Close-icon1.png"))); // NOI18N
        jButtonCancelar.setText("CANCELAR");

        jButtonConsultar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Archivos/Button-Refresh-icon1.png"))); // NOI18N
        jButtonConsultar.setText("CONSULTAR");

        jButtonVolver.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Archivos/home-icon1.png"))); // NOI18N
        jButtonVolver.setText("VOLVER");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Actualizar Arbitros"));

        jTextFieldCedula.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldCedulaFocusLost(evt);
            }
        });
        jTextFieldCedula.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextFieldCedulaKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldCedulaKeyTyped(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel2.setText("Cedula");

        jLabel3.setText("Nombre");

        jTextFieldNombre.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldNombreKeyTyped(evt);
            }
        });

        jLabel4.setText("Apellido");

        try {
            jFormattedTextFieldFechaNac.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jLabel5.setText("Fecha Nac");

        jLabel6.setText("No Partidos");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel2)
                    .addComponent(jFormattedTextFieldFechaNac, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldCedula, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(15, 15, 15)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jTextFieldNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(36, 36, 36)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jTextFieldApellido, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jTextFieldJuegos, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTextFieldNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextFieldCedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jFormattedTextFieldFechaNac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldJuegos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(59, Short.MAX_VALUE))
        );

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Archivos/TituloRegArbitro.png"))); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(55, 55, 55)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButtonVolver)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(70, 70, 70)
                        .addComponent(jButtonGuardar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonEliminar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonCancelar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonConsultar))
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addGap(82, 82, 82)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonConsultar, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonVolver, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(110, 110, 110))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-656)/2, (screenSize.height-518)/2, 656, 518);
    }// </editor-fold>//GEN-END:initComponents

private void jTextFieldCedulaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldCedulaFocusLost
// TODO add your handling code here:
    int PosiArbitro=0;
Arbitros arbitro;

    PosiArbitro=Arbitros.ExisteArbitro(jTextFieldCedula.getText());
    
    if (PosiArbitro>=0)
      {  
        arbitro=Arbitros.ListaArbitros.get(PosiArbitro); 
       String cantJuegos= String.valueOf(arbitro.GetCantJuegos());
        jTextFieldNombre.setText(arbitro.GetNombre());
        jTextFieldApellido.setText(arbitro.GetApellido());
        jFormattedTextFieldFechaNac.setText(arbitro.GetFechaNac());
        jTextFieldJuegos.setText(cantJuegos);
        jTextFieldNombre.enable(false);
        jTextFieldApellido.enable(false);
        jFormattedTextFieldFechaNac.enable(false);
        jTextFieldJuegos.enable(false);
      }
   posicion=PosiArbitro;
}//GEN-LAST:event_jTextFieldCedulaFocusLost

private void jTextFieldCedulaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldCedulaKeyPressed

    
}//GEN-LAST:event_jTextFieldCedulaKeyPressed

private void jTextFieldCedulaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldCedulaKeyTyped
String Cadena;

Cadena=jTextFieldCedula.getText();

char caracter = evt.getKeyChar();
if( caracter < '0' || caracter > '9') 
  evt.consume(); 
else
    if (Cadena.length()==10)
      evt.consume();  
}//GEN-LAST:event_jTextFieldCedulaKeyTyped

private void jTextFieldNombreKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldNombreKeyTyped
String Cadena,CarString;

Cadena=jTextFieldNombre.getText();
char caracter = evt.getKeyChar();

CarString=caracter+"";

CarString=CarString.toUpperCase();

caracter=CarString.charAt(0);

if (caracter==' ')
 {  
    if (Cadena.length()==20)
      evt.consume();    
    
    return;
 }  
    
if( caracter < 'A' || caracter > 'Z') 
{  
  evt.consume(); 
  return;
}

if (Cadena.length()==20)
   evt.consume();    
}//GEN-LAST:event_jTextFieldNombreKeyTyped
public void btnCancelar() {
    jTextFieldCedula.setText("");
    jTextFieldNombre.setText("");
    jTextFieldApellido.setText("");
    jFormattedTextFieldFechaNac.setText("");
    jTextFieldJuegos.setText("");
    jTextFieldCedula.requestFocusInWindow ();
    jTextFieldNombre.enable(true);
    jTextFieldApellido.enable(true);
    jFormattedTextFieldFechaNac.enable(true);
    jTextFieldJuegos.enable(true);
}
public void btnGuardar()
{
    String Cadena;

Cadena=jTextFieldCedula.getText();
if (Cadena.length()==0)
{
  Mensajes.Aviso("Cedula Vacia", "Arbitros");  
  jTextFieldCedula.requestFocusInWindow ();
  return;
}    

Cadena=jTextFieldNombre.getText();
if (Cadena.length()==0)
{
  Mensajes.Aviso("Nombre Vacio", "Arbitros");  
  jTextFieldNombre.requestFocusInWindow ();
  return;
}    

Cadena=jTextFieldApellido.getText();
if (Cadena.length()==0)
{
  Mensajes.Aviso("Apellido Vacio", "Arbitros");  
  jTextFieldApellido.requestFocusInWindow ();
  return;
}    

Cadena=jFormattedTextFieldFechaNac.getText();
if (!Validaciones.isDate(Cadena))
{
  Mensajes.Aviso("Error en Fecha", "Arbitros");  
  jFormattedTextFieldFechaNac.requestFocusInWindow ();
  return;    
}    

//Grabar en la Lista
 Arbitros.addArbitro(jTextFieldCedula.getText(),
                     jTextFieldNombre.getText(),
                     jTextFieldApellido.getText(),
                     jFormattedTextFieldFechaNac.getText(),
                     0);
 
 btnCancelar();
 Mensajes.Informacion("Arbitro Guardado", "Informacion");
}
public void btnEliminar(){
    Arbitros.ListaArbitros.remove(posicion);
  Mensajes.Informacion("El arbitro ha sido eliminado.", "Mensaje");
}
        
public void AddListener (ActionListener listener)  
{
    jButtonCancelar.addActionListener(listener);
    jButtonConsultar.addActionListener(listener);
    jButtonEliminar.addActionListener(listener);
    jButtonGuardar.addActionListener(listener);
    jButtonVolver.addActionListener(listener);
}   
/**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FormRegistrarArbitros.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FormRegistrarArbitros.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FormRegistrarArbitros.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FormRegistrarArbitros.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new FormRegistrarArbitros().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCancelar;
    private javax.swing.JButton jButtonConsultar;
    private javax.swing.JButton jButtonEliminar;
    private javax.swing.JButton jButtonGuardar;
    private javax.swing.JButton jButtonVolver;
    private javax.swing.JFormattedTextField jFormattedTextFieldFechaNac;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jTextFieldApellido;
    private javax.swing.JTextField jTextFieldCedula;
    private javax.swing.JTextField jTextFieldJuegos;
    private javax.swing.JTextField jTextFieldNombre;
    // End of variables declaration//GEN-END:variables
}
